local STREAK_TYPE = {
    win = 1,    --普通击杀
    beat = 2,   --终结
    winThree = 3,--3连
}
---@class DarkStreetBroadcastItem : UIComponentInterface
local DarkStreetBroadcastItem = Class("DarkStreetMineralItem",UIComponentInterface)
function DarkStreetBroadcastItem:OnCreate(obj,finishCallback,tb)
    self.fguiObj = obj
    self.winText = self:GetChild("Text_PlayerName1")
    self.failedText = self:GetChild("Text_PlayerName2")
    self.numText = self:GetChild("Text_RewardNum")
    self.transition = self:GetTransition("Effect_Kill")
    local head1 = self:GetChild("Btn_Head01")
    self.icon1 = self:GetChild("head/HeadIcon",head1)
    self.frame1 = self:GetChild("frame",head1)
    local head2 = self:GetChild("Btn_Head02")
    self.icon2 = self:GetChild("head/HeadIcon",head2)
    self.frame2 = self:GetChild("frame",head2)
    self.ctrlKill = self:GetController("kill")
    self.ctrlType = self:GetController("Type")
    local singleHead = self:GetChild("Btn_HeadSingle")
    self.singleIcon = self:GetChild("head/HeadIcon",singleHead)
    self.singleFrame = self:GetChild("frame",singleHead)
    self.singleName = self:GetChild("Text_PlayerNameSingle")

    self.finishCallback = finishCallback
    self.finishTb = tb
    self.fguiObj.visible = false
end

function DarkStreetBroadcastItem:OnDestroy()

end
function DarkStreetBroadcastItem:Set(msg,x,y)
    AudioManager.Play(2034)
    self.fguiObj.visible = true
    local winPlayer = RedRob.ActorManager.GetActor(msg.winId)
    local failedPlayer = RedRob.ActorManager.GetActor(msg.failedId)
    if not winPlayer or not failedPlayer then return end
    self.winText.text = winPlayer:GetName()
    self.failedText.text = failedPlayer:GetName()
    self.numText.text = tostring(msg.count)
    self.fguiObj:SetXY(x,y)
    local winData = RedRob.GameMode.GetPlayerData(msg.winId)
    local failData = RedRob.GameMode.GetPlayerData(msg.failedId)

    UIComponentInterface:SetPlayerIcon(self.icon1,winPlayer:GetModelId(),self.frame1,winPlayer:GetPicFrame())
    UIComponentInterface:SetPlayerIcon(self.icon2,failedPlayer:GetModelId(),self.frame2,failedPlayer:GetPicFrame())
    UIComponentInterface:SetPlayerIcon(self.singleIcon,winPlayer:GetModelId(),self.singleFrame,winPlayer:GetPicFrame())
    self.singleName.text = failedPlayer:GetName()
    self:Defeat(msg)
end
function DarkStreetBroadcastItem:Defeat(msg)
    local winData = RedRob.GameMode.GetPlayerData(msg.winId)
    local failData = RedRob.GameMode.GetPlayerData(msg.failedId)
    if failData.winStreakCount >= 3 then
        --终结 双头像
        self.ctrlKill.selectedIndex = 5
        self.ctrlType.selectedIndex = 1
        self.transition:Play(function()
            self:WinStreak(msg,STREAK_TYPE.beat)
        end)
    else
        self:WinStreak(msg,STREAK_TYPE.win)
    end
end
function DarkStreetBroadcastItem:WinStreak(msg,state)
    if not TBS.Battle.isStart then return end
    local winPlayer = RedRob.ActorManager.GetActor(msg.winId)
    local failedPlayer = RedRob.ActorManager.GetActor(msg.failedId)
    local winData = RedRob.GameMode.GetPlayerData(msg.winId)
    local failData = RedRob.GameMode.GetPlayerData(msg.failedId)
    if winData.winStreakCount <= 2 then --2连杀一下
        if state == STREAK_TYPE.beat then  --终结不在提示
            if self.finishCallback then
                self.finishCallback(self.finishTb,self)
            end
            return
        end
        --击杀 双头像
        self.ctrlKill.selectedIndex = 0
        self.ctrlType.selectedIndex = 1
    else
        --击杀 双头像
        if state == STREAK_TYPE.win then
            local index = math.min(winData.winStreakCount -2,4)
            self.ctrlKill.selectedIndex = 0
            self.ctrlType.selectedIndex = 1
            self.transition:Play(function()
                self:WinStreak(msg,STREAK_TYPE.winThree)
            end)
            return
        end
        --3杀以上 单头像
        local index = math.min(winData.winStreakCount -2,4)
        self.ctrlKill.selectedIndex = index
        self.ctrlType.selectedIndex = 0
        UIComponentInterface:SetPlayerIcon(self.singleIcon,winPlayer:GetModelId(),self.singleFrame,winPlayer:GetPicFrame())
        self.singleName.text = winPlayer:GetName()
    end
    self.transition:Play(function()
        if self.finishCallback then
            self.finishCallback(self.finishTb,self)
        end
    end)
end

return DarkStreetBroadcastItem